dnl -*- mode: shell-script -*-
dnl Process this file with autoconf to produce a configure script.
dnl
dnl Permission is hereby granted, free of charge, to any person obtaining a
dnl copy of this software and associated documentation files (the "Software"),
dnl to deal in the Software without restriction, subject to the conditions
dnl listed in the Click LICENSE file. These conditions include: you must
dnl preserve this copyright notice, and you cannot mention the copyright
dnl holders in advertising related to the Software without their permission.
dnl The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
dnl notice is a summary of the Click LICENSE file; the license in that file is
dnl legally binding.

AC_INIT(click, 1.6.0)
AC_PREREQ(2.50)
AC_CONFIG_HEADER(include/click/config.h:config.h.in include/click/pathvars.h:pathvars.h.in include/click/config-bsdmodule.h:config-bsdmodule.h.in include/click/config-linuxmodule.h:config-linuxmodule.h.in include/click/config-ns.h:config-ns.h.in include/click/config-userlevel.h:config-userlevel.h.in)

CLICK_VERSION=$PACKAGE_VERSION

AC_SUBST(ac_configure_args)
AC_DEFINE_UNQUOTED(CLICK_VERSION, "$CLICK_VERSION")
AC_SUBST(CLICK_VERSION)

CLICK_INIT('$(top_srcdir)')

dnl support for cross compiling
AC_CANONICAL_SYSTEM

dnl This is wrong!!
AC_CHECK_TOOL(CC, gcc)
AC_CHECK_TOOL(CXX, g++)

CLICK_PROG_CC
AC_PROG_CPP
AC_C_INLINE

CLICK_PROG_CXX
AC_PROG_CXXCPP

CLICK_PROG_KERNEL_CC
CLICK_PROG_KERNEL_CXX

ac_preset_ar="$AR"
AC_CHECK_TOOL(AR, ar)
AC_CHECK_TOOL(LD, ld)
AC_CHECK_TOOL(RANLIB, ranlib, :)
AC_CHECK_TOOL(STRIP, strip, :)

conf_auxdir='$(top_srcdir)'
AC_SUBST(conf_auxdir)

test -z "$AR_CREATEFLAGS" && AR_CREATEFLAGS=cru
AC_SUBST(AR_CREATEFLAGS)


dnl
dnl check drivers to enable
dnl

dnl userlevel driver and features

AC_ARG_ENABLE(userlevel, [  --disable-userlevel     disable user-level driver], :, enable_userlevel=yes)

AC_ARG_ENABLE(user-multithread, [[    --enable-user-multithread support userlevel multithreading (EXPERIMENTAL)]], :, [enable_user_multithread=no])
if test "x$enable_user_multithread" = xyes; then
    AC_DEFINE(HAVE_USER_MULTITHREAD)
fi


dnl linuxmodule driver and features

AC_ARG_ENABLE(linuxmodule, [  --disable-linuxmodule   disable Linux kernel driver], :, [enable_linuxmodule=yes; enable_linuxmodule_default=yes])

AC_ARG_ENABLE(multithread,
  [[    --enable-multithread[=N]  support kernel multithreading, N threads max]],
  :, enable_multithread=no)

test "$enable_multithread" = yes && enable_multithread=4
test "$enable_multithread" = no && enable_multithread=1
if test "$enable_multithread" -gt 1; then
    AC_DEFINE_UNQUOTED(NUM_CLICK_CPUS, $enable_multithread)
    AC_DEFINE_UNQUOTED(__MTCLICK__, 1)
    saveflags="$CPPFLAGS"
    CPPFLAGS="$saveflags -D__MTCLICK__"
else
    AC_DEFINE_UNQUOTED(NUM_CLICK_CPUS, 1)
fi

AC_ARG_ENABLE(warp9, [[    --enable-warp9            reduce PollDevice functionality for speed]], :, enable_warp9=no)
if test "x$enable_warp9" = xyes; then
    AC_DEFINE(CLICK_WARP9)
fi

AC_DEFINE(HAVE_CLICKFS)

AC_ARG_ENABLE(kassert, [[    --enable-kassert          enable kernel assertions]], :, enable_kassert=no)
if test $enable_kassert = yes; then
    AC_DEFINE(HAVE_KERNEL_ASSERT)
fi

AC_ARG_ENABLE(adaptive, [[    --enable-adaptive         use adaptive scheduler to flexibly arbitrate
                              between Click and the kernel (EXPERIMENTAL)]], :, enable_adaptive=no)
if test "x$enable_adaptive" = xyes; then
    AC_DEFINE(HAVE_ADAPTIVE_SCHEDULER)
fi



dnl bsdmodule driver and features

AC_ARG_ENABLE(bsdmodule, [  --enable-bsdmodule      enable FreeBSD kernel driver (EXPERIMENTAL)], :, enable_bsdmodule=no)

dnl nsclick driver and features

AC_ARG_ENABLE(nsclick, [  --enable-nsclick        enable NS simulator driver (EXPERIMENTAL)], :, enable_nsclick=no)


dnl
dnl How to build linuxmodule driver?
dnl

AC_ARG_WITH(linux, [[  --with-linux[=DIR]      Linux source code is in DIR]],
    [linuxdir=$withval], [linuxdir=NONE])
test -z "$linuxdir" -o "$linuxdir" = yes && linuxdir=yes

AC_ARG_WITH(linux-map, [[  --with-linux-map[=FILE] filename for Linux System.map [LINUXDIR/System.map]]],
  [linux_system_map=$withval; if test -z "$withval" -o "$withval" = yes; then linux_system_map=NONE; fi],
  linux_system_map=NONE)

linux_system_map_boot=no

if test "x$linuxdir" = xNONE -o "x$linuxdir" = xyes; then
    if uname -r 2>/dev/null | grep '^2\.6' >/dev/null 2>&1; then
	linuxdir=/lib/modules/"`uname -r`"/build
	linux_system_map_boot="`uname -r`"
    else
	linuxdir=/usr/src/linux
    fi
    if test ! -d "$linuxdir" -a "x$enable_linuxmodule" = xyes; then
	if test "x$enable_linuxmodule_default" = xyes; then
	    linuxdir=NONE; enable_linuxmodule=no
	else
	    AC_MSG_ERROR([
=========================================

Can't find $linuxdir, so I can't compile the linuxmodule driver!
(You may need the --with-linux=DIR option.)

=========================================])
	fi
    fi
fi

if test "x$linuxdir" = xNONE -o "x$linuxdir" = xno -o "x$enable_linuxmodule" != xyes; then
    ac_have_linux_kernel=n
    linuxdir=NONE
elif expr "_$linuxdir" : '_[[^/\\]]' >/dev/null; then 
    AC_MSG_ERROR([
=========================================

The --with-linux directory $linuxdir is relative.
You must supply an absolute path starting with /.

=========================================])
elif test -r $linuxdir/include/linux/skbuff.h; then
    ac_have_linux_kernel=y
else
    AC_MSG_ERROR([
=========================================

Can't find $linuxdir/include/linux/skbuff.h.
Are you sure $linuxdir contains Linux kernel source?

=========================================])
fi
AC_SUBST(linuxdir)
AC_DEFINE_UNQUOTED(LINUX_SRCDIR, "${linuxdir}")



dnl
dnl element collections
dnl

AC_ARG_ENABLE(all-elements, [  --enable-all-elements   include all provided element groups])

dnl ELEMENTS_ARG_ENABLE(COLLECTION, HELP-STRING, DEFAULT-VALUE)
element_groups=""
AC_SUBST(element_groups)
AC_DEFUN([ELEMENTS_ARG_ENABLE],
[AC_ARG_ENABLE($1, [  --]builtin(substr, builtin(ifelse, [$3], yes, dis, en)[able-$1              ], 0, 21)[ ]builtin(ifelse, [$3], yes, [do not ], [])[$2], ,
[enable_]patsubst([$1], -, _)=$3)dnl
test "x$enable_all_elements" = xyes -a ["x$enable_]patsubst([$1], -, _)["] = xNO && [enable_]patsubst([$1], -, _)[=yes]
if test ["x$enable_]patsubst([$1], -, _)["] = xyes; then
    :
    $4
fi])

ELEMENTS_ARG_ENABLE(analysis, [include elements for network analysis], NO)
ELEMENTS_ARG_ENABLE(app, [include application-level elements], yes)
ELEMENTS_ARG_ENABLE(aqm, [include active queue management elements], yes)
ELEMENTS_ARG_ENABLE(ethernet, [include Ethernet elements], yes)
ELEMENTS_ARG_ENABLE(etherswitch, [include Ethernet switch elements (EXPERIMENTAL)], NO)
ELEMENTS_ARG_ENABLE(grid, [include Grid elements (see FAQ)], NO)
ELEMENTS_ARG_ENABLE(icmp, [include ICMP elements], yes)
ELEMENTS_ARG_ENABLE(ip, [include IP elements], yes)
ELEMENTS_ARG_ENABLE(ip6, [include IPv6 elements (EXPERIMENTAL)], NO, AC_DEFINE(HAVE_IP6))
ELEMENTS_ARG_ENABLE(ipsec, [include IP security elements], NO, AC_DEFINE(HAVE_IPSEC))
ELEMENTS_ARG_ENABLE(local, [include local elements], NO)
ELEMENTS_ARG_ENABLE(radio, [include radio elements (EXPERIMENTAL)], NO)
ELEMENTS_ARG_ENABLE(simple, [include simple versions of other elements], NO)
dnl ELEMENTS_ARG_ENABLE(snmp, [include SNMP elements], NO)
ELEMENTS_ARG_ENABLE(standard, [include standard elements], yes)
ELEMENTS_ARG_ENABLE(tcpudp, [include TCP and UDP elements], yes)
ELEMENTS_ARG_ENABLE(test, [include regression test elements], NO)
ELEMENTS_ARG_ENABLE(wifi, [include wifi elements and support], NO)
AC_ARG_ENABLE(experimental, [  --enable-experimental   enable experimental elements in normal groups], :, enable_experimental=no)

for i in `(cd $srcdir/elements; ls | sed '/^CVS$/d;/^bsdmodule$/d;/^exopc$/d;/^linuxmodule$/d;/^ns$/d;/^userlevel$/d')`; do
    enableval=`eval 'echo $'"enable_$i"`
    test "x$enable_all_elements" = xyes -a "x$enableval" '!=' 'no' && enableval=yes
    test -d "$srcdir/elements/$i" -a "$enableval" = "yes" && element_groups="$element_groups $i"
done



dnl
dnl How to build bsdmodule driver?
dnl

AC_ARG_WITH(freebsd, [[  --with-freebsd[=SRC,INC] FreeBSD source code is in SRC [/usr/src/sys],
                          include directory is INC [/usr/include]]],
  [freebsddir=$withval; if test -z "$withval" -o "$withval" = yes; then freebsddir=/usr/src/sys,/usr/include; fi],
  freebsddir=NONE)

if test "x$freebsddir" = xNONE; then
  if test -d /usr/src/sys -a -d /usr/include; then
    freebsddir=/usr/src/sys,/usr/include
  elif test "x$enable_bsdmodule" = xyes; then
    AC_MSG_WARN([
=========================================

Can't find /usr/src/sys and/or /usr/include, so I'm not compiling
the bsdmodule driver.  (You may need the --with-freebsd=DIR option.)

=========================================])
  fi
fi

freebsd_srcdir=`echo "$freebsddir," | sed -e 's/,.*//'`
freebsd_includedir=`echo "$freebsddir,/usr/include," | sed -e 's/^[[^,]]*,\([[^,]]*\),.*$/\1/'`

if test "x$freebsddir" = xNONE -o "x$freebsddir" = xno -o "x$enable_bsdmodule" != xyes; then
  ac_have_bsd_kernel=n
  freebsddir=NONE
elif expr '(' "_$freebsd_includedir" : '_[[^/\\]]' ')' '|' '(' "_$freebsd_srcdir" : '_[[^/\\]]' ')'; then 
  AC_MSG_ERROR([
=========================================

The --with-freebsd directories $freebsd_srcdir,$freebsd_includedir
are relative.  You must supply absolute paths starting with /.

=========================================])
elif test -r $freebsd_includedir/net/if_var.h -a -r $freebsd_srcdir/kern/vnode_if.src; then
  ac_have_bsd_kernel=y
else
  AC_MSG_ERROR([
=========================================

Can't find $freebsd_includedir/net/if_var.h and/or
$freebsd_srcdir/kern/vnode_if.src.  Are you sure $freebsd_srcdir
and $freebsd_includedir contain FreeBSD kernel source?

=========================================])
fi

AC_SUBST(freebsd_srcdir)
AC_SUBST(freebsd_includedir)
AC_DEFINE_UNQUOTED(FREEBSD_INCLUDEDIR, "${freebsd_includedir}")


dnl
dnl check whether target is Linux
dnl

AC_CACHE_CHECK([whether we are compiling for Linux], [ac_cv_under_linux],
    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[#ifndef __linux__
#error "fuckers! fuckers!"
#endif
return 0;]])], ac_cv_under_linux=yes, ac_cv_under_linux=no)])


dnl
dnl functions
dnl

AC_LANG_C
AC_REPLACE_FUNCS(strerror)
AC_CHECK_FUNCS(snprintf strtoul tcgetpgrp vsnprintf)
AC_LANG_CPLUSPLUS


dnl
dnl integer types, endianness, int64, addressable va_list
dnl

AC_ARG_ENABLE(int64, [  --disable-int64         disable 64-bit integer support], :, enable_int64=yes)

AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
CLICK_CHECK_INTEGER_TYPES
CLICK_CHECK_ALIGNMENT
if test "x$enable_int64" = xyes; then
    AC_CHECK_SIZEOF(long long)
    CLICK_CHECK_INT64_TYPES
fi
AC_CHECK_SIZEOF([struct timeval])
AC_CHECK_TYPES([struct timespec], have_timespec=yes, have_timespec=no)
if test "x$have_timespec" = xyes; then
    AC_CHECK_SIZEOF([struct timespec])
fi
CLICK_CHECK_ENDIAN
CLICK_CHECK_SIGNED_SHIFT
CLICK_CHECK_ADDRESSABLE_VA_LIST
CLICK_CHECK_INTEGER_BUILTINS


dnl
dnl nanosecond-precision timestamps
dnl

AC_ARG_ENABLE(nanotimestamp, [  --enable-nanotimestamp  enable nanosecond timestamps])
if test "x$enable_nanotimestamp" = xyes; then
    AC_DEFINE(HAVE_NANOTIMESTAMP_ENABLED)
fi


dnl
dnl check whether tools should be built for host or build
dnl

AC_ARG_ENABLE(tools,
  [[  --enable-tools=WHERE    enable tools (host/build/mixed/no) [mixed]]],
  :, enable_tools=mixed)

if test "$enable_tools" != mixed -a "$enable_tools" != host -a "$enable_tools" != build -a "$enable_tools" != no; then
  AC_MSG_ERROR([
=========================================

Bad value for --enable-tools.  Try 'host', 'build', 'mixed', or 'no'.

=========================================])
elif test "$enable_tools" = no; then
  HOST_TOOLS=host
elif test "$cross_compiling" = no -o "$enable_tools" = host; then
  HOST_TOOLS=host
else
  dnl This is wrong!! Should at least check that HOST_CC and HOST_CXX work.
  AC_CHECK_PROGS(BUILD_CC, gcc)
  AC_CHECK_PROGS(BUILD_CXX, g++)
  CLICK_PROG_BUILD_CXX
  AC_CHECK_PROGS(BUILD_AR, ar)
  AC_CHECK_PROGS(BUILD_RANLIB, ranlib, :)
  HOST_TOOLS=$enable_tools
fi
AC_SUBST(HOST_TOOLS)


dnl
dnl headers, event detection, dynamic linking
dnl

AC_CHECK_HEADERS(unistd.h termio.h netdb.h sys/event.h pwd.h grp.h)
CLICK_CHECK_POLL_H
AC_CHECK_FUNCS(sigaction)

AC_CHECK_FUNCS(kqueue, have_kqueue=yes)
if test "x$have_kqueue" = xyes; then
    AC_CACHE_CHECK([whether EV_SET last argument is void *], [ac_cv_ev_set_udata_pointer],
	[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>]], [[struct kevent kev; EV_SET(&kev, 1, EVFILT_WRITE, EV_ADD, 0, 0, (void *) &kev);]])], [ac_cv_ev_set_udata_pointer=yes], [ac_cv_ev_set_udata_pointer=no])])
    if test $ac_cv_ev_set_udata_pointer = yes; then
	AC_DEFINE([HAVE_EV_SET_UDATA_POINTER], [1], [Define if the last argument to EV_SET has pointer type.])
    fi
fi

AC_ARG_ENABLE(dynamic-linking, [  --disable-dynamic-linking disable dynamic linking], :, enable_dynamic_linking=yes)

if test "x$enable_dynamic_linking" = xyes; then
    CLICK_CHECK_DYNAMIC_LINKING
    if test "$HOST_TOOLS" != host -a "$enable_tools" != no; then
	CLICK_CHECK_BUILD_DYNAMIC_LINKING
    fi
fi


dnl
dnl sockets
dnl

AC_LANG_C
SOCKET_LIBS=
if test "$enable_userlevel" = yes; then
    savelibs="$LIBS"; LIBS=
    AC_SEARCH_LIBS(gethostbyname, nsl, , , $savelibs)
    AC_SEARCH_LIBS(connect, socket, , , $savelibs)
    SOCKET_LIBS="$LIBS"; LIBS="$savelibs"

    AC_CACHE_CHECK([whether accept() uses socklen_t], [ac_cv_accept_socklen_t],
	    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#include <sys/socket.h>
]], [[socklen_t sl; (void) accept(0, (struct sockaddr *) 0, &sl);]])],
	ac_cv_accept_socklen_t=yes, ac_cv_accept_socklen_t=no)])
    if test "$ac_cv_accept_socklen_t" = yes; then
	AC_DEFINE([HAVE_ACCEPT_SOCKLEN_T], [1], [Define if accept() uses socklen_t.])
    fi
fi
AC_SUBST(SOCKET_LIBS)
AC_LANG_CPLUSPLUS


dnl
dnl large file support
dnl

CLICK_CHECK_LARGE_FILE_SUPPORT


dnl
dnl mmap
dnl

AC_LANG_C
AC_CHECK_HEADERS(sys/mman.h)
AC_FUNC_MMAP
AC_LANG_CPLUSPLUS
AC_CHECK_FUNCS(madvise)
AC_CHECK_DECLS(madvise, [], [], [#if HAVE_SYS_MMAN_H
#include <sys/types.h>
#include <sys/mman.h>
#endif])


dnl
dnl objects required by element collections
dnl

EXTRA_DRIVER_OBJS=
EXTRA_TOOL_OBJS=
if test "x$enable_ip6" = xyes; then
    EXTRA_DRIVER_OBJS="ip6address.o ip6flowid.o ip6table.o $EXTRA_DRIVER_OBJS"
    EXTRA_TOOL_OBJS="ip6address.o $EXTRA_TOOL_OBJS"
fi
AC_SUBST(EXTRA_DRIVER_OBJS)
AC_SUBST(EXTRA_TOOL_OBJS)


dnl
dnl stuff in the linux kernel
dnl

if test $ac_have_linux_kernel = y; then

dnl Look for System.map

if test "$linux_system_map" = NONE; then
    linux_system_map=$linuxdir/System.map
    if test "x$linux_system_map_boot" != xno -a ! -f "$linux_system_map"; then
	linux_system_map=/boot/System.map-"$linux_system_map_boot"
    fi
fi

if test ! -f "$linux_system_map"; then
    if test "x$enable_linuxmodule_default" = xyes; then
	AC_MSG_WARN([
=========================================

Can't find Linux System.map file '$linux_system_map',
so I won't compile the linuxmodule driver.
(You may need the --with-linux=DIR and/or --with-linux-map=MAP options.)

=========================================])
	ac_have_linux_kernel=no
    else
	AC_MSG_ERROR([
=========================================

Can't find Linux System.map file '$linux_system_map'.
(You may need the --with-linux=DIR and/or --with-linux-map=MAP options.)

=========================================])
    fi
fi

fi

dnl Check for Linux 2.6

if test $ac_have_linux_kernel = y; then

AC_CACHE_CHECK([for Linux 2.6], [ac_cv_linux26],
    [if grep '^PATCHLEVEL[ 	]*=[ 	]*6' $linuxdir/Makefile >/dev/null 2>&1; then ac_cv_linux26=1; else ac_cv_linux26=0; fi])
LINUXMODULE_2_6=$ac_cv_linux26
AC_SUBST(LINUXMODULE_2_6)
if test $LINUXMODULE_2_6 = 1; then
    AC_DEFINE([HAVE_LINUXMODULE_2_6], [1], [Define if the Click linuxmodule is compiled for a 2.6 kernel.])
fi

AC_CACHE_CHECK(for Click Linux kernel extensions, ac_cv_click_kernel,
[if grep register_net_in $linux_system_map >/dev/null 2>&1; then
    ac_cv_click_kernel=yes
else ac_cv_click_kernel=no; fi])
if test $ac_cv_click_kernel = yes; then
    AC_DEFINE(HAVE_CLICK_KERNEL)
fi

AC_CACHE_CHECK(for Click Linux kernel extensions for transmit notification, ac_cv_click_kernel_tx_notify,
[if grep register_net_tx $linux_system_map >/dev/null 2>&1; then
    ac_cv_click_kernel_tx_notify=yes
else ac_cv_click_kernel_tx_notify=no; fi])
if test $ac_cv_click_kernel_tx_notify = yes; then
    AC_DEFINE(HAVE_CLICK_KERNEL_TX_NOTIFY)
fi

AC_CACHE_CHECK(for read_net_skbcount kernel extension, ac_cv_linux_read_net_skbcount,
[if grep read_net_skbcount $linux_system_map >/dev/null 2>&1; then
  ac_cv_linux_read_net_skbcount=yes
else ac_cv_linux_read_net_skbcount=no; fi])
if test $ac_cv_linux_read_net_skbcount = yes; then
    AC_DEFINE(HAVE_LINUX_READ_NET_SKBCOUNT)
fi

AC_CACHE_CHECK(for strlen kernel symbol, ac_cv_linux_strlen_exposed,
[if grep ' strlen' $linux_system_map >/dev/null 2>&1; then
  ac_cv_linux_strlen_exposed=yes
else ac_cv_linux_strlen_exposed=no; fi])
if test $ac_cv_linux_strlen_exposed = yes; then
    AC_DEFINE(HAVE_LINUX_STRLEN_EXPOSED)
fi

AC_CACHE_CHECK(for tulip_interrupt_hook kernel symbol, ac_cv_linux_tulip_intr_hook,
[if grep ' tulip_interrupt_hook' $linux_system_map >/dev/null 2>&1; then
  ac_cv_linux_tulip_intr_hook=yes
else ac_cv_linux_tulip_intr_hook=no; fi])
if test $ac_cv_linux_tulip_intr_hook = yes; then
    AC_DEFINE(HAVE_LINUX_TULIP_INTERRUPT_HOOK)
fi

AC_CACHE_CHECK(for device polling kernel extension, ac_cv_linux_poll_extension,
[if grep polling $linuxdir/include/linux/netdevice.h >/dev/null 2>&1; then
  ac_cv_linux_poll_extension=yes
else ac_cv_linux_poll_extension=no; fi])
if test $ac_cv_linux_poll_extension = yes; then
    AC_DEFINE(HAVE_LINUX_POLLING)
fi

AC_CACHE_CHECK(for atomic_set_mask, ac_cv_linux_atomic_set_mask,
[if grep atomic_set_mask $linuxdir/include/asm/atomic.h >/dev/null 2>&1; then
  ac_cv_linux_atomic_set_mask=yes
else ac_cv_linux_atomic_set_mask=no; fi])
if test $ac_cv_linux_atomic_set_mask = yes; then
    AC_DEFINE(HAVE_LINUX_ATOMIC_SET_MASK)
fi

AC_CACHE_CHECK(for SMP, ac_cv_smp,
[if grep "#define CONFIG_SMP 1" $linuxdir/include/linux/autoconf.h >/dev/null 2>&1; then
  ac_cv_smp=yes
else ac_cv_smp=no; fi])
if test $ac_cv_smp = yes; then
    AC_DEFINE(__SMP__)
    KERNEL_CXX="$KERNEL_CXX -D__SMP__"
fi

AC_CACHE_CHECK(for <asm/alternative.h>, ac_cv_linux_asm_alternative_h,
[if test -r $linuxdir/include/asm/alternative.h >/dev/null 2>&1; then
  ac_cv_linux_asm_alternative_h=yes
else ac_cv_linux_asm_alternative_h=no; fi])
if test $ac_cv_linux_asm_alternative_h = yes; then
    AC_DEFINE(HAVE_LINUX_ASM_ALTERNATIVE_H)
fi

fi


dnl
dnl stuff in the bsd kernel
dnl

if test $ac_have_bsd_kernel = y; then
    KERNEL_CXX="$KERNEL_CXX -fpermissive"
    AC_CACHE_CHECK(FreeBSD version, ac_cv_freebsd_version, [
	save_flags="$CPPFLAGS"
	CPPFLAGS="$CPPFLAGS -I$freebsd_includedir"
	AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <sys/param.h>
#if __FreeBSD_version < 500000
#include <NONEXISTENT_FILE>
#endif]])], ac_cv_freebsd_version=yes, ac_cv_freebsd_version=no)
	CPPFLAGS="$save_flags"])
    if test $ac_cv_freebsd_version = yes; then
	AC_DEFINE(HAVE_CLICK_BSD_KERNEL)
	AC_DEFINE(HAVE_BSD_POLLING)
    else
	AC_MSG_WARN([
=========================================

Your version of FreeBSD is old.  Click works with FreeBSD 5.x and later.

=========================================])
    fi
fi


dnl
dnl type of scheduling
dnl

AC_ARG_ENABLE(stride, [  --disable-stride        disable stride scheduler], :, enable_stride=yes)
if test $enable_stride = yes; then
    AC_DEFINE(HAVE_STRIDE_SCHED)
fi

AC_ARG_ENABLE(task-heap, [  --enable-task-heap      use heap for task list], :, enable_task_heap=no)
if test $enable_task_heap = yes; then
    AC_DEFINE(HAVE_TASK_HEAP)
fi


dnl
dnl debugging malloc
dnl

AC_ARG_ENABLE(dmalloc, [  --enable-dmalloc        enable debugging malloc], :, enable_dmalloc=no)
if test $enable_dmalloc = yes; then
    AC_DEFINE(CLICK_DMALLOC)
fi


dnl
dnl use Intel-specific machine instructions
dnl

AC_ARG_ENABLE(intel-cpu, [  --enable-intel-cpu      enable Intel-specific machine instructions], :, enable_intel_cpu=no)
if test $enable_intel_cpu = yes; then
    AC_DEFINE(HAVE_INTEL_CPU)
fi


dnl
dnl kernel interfaces
dnl

AC_CHECK_HEADERS(linux/if_tun.h net/if_tun.h net/if_tap.h net/bpf.h)


dnl
dnl possible drivers
dnl

POSSIBLE_DRIVERS=
for i in bsdmodule exopc linuxmodule ns userlevel; do
    test -f $srcdir/$i/Makefile.in && POSSIBLE_DRIVERS="$POSSIBLE_DRIVERS $i"
done
AC_SUBST(POSSIBLE_DRIVERS)


dnl
dnl default drivers
dnl

DRIVERS=
AC_SUBST(DRIVERS)

HAVE_USERLEVEL_DRIVER=0
AC_SUBST(HAVE_USERLEVEL_DRIVER)
HAVE_LINUXMODULE_DRIVER=0
AC_SUBST(HAVE_LINUXMODULE_DRIVER)
HAVE_BSDMODULE_DRIVER=0
AC_SUBST(HAVE_BSDMODULE_DRIVER)

OTHER_TARGETS=
AC_SUBST(OTHER_TARGETS)

for i in click-align click-check click-combine click-devirtualize click-fastclassifier click-flatten click-ipopt click-mkmindriver click-pretty click-undead click-xform click2xml; do
    test -d $srcdir/tools/$i &&	\
	TOOLDIRS="$TOOLDIRS $i" TOOL_TARGETS="$TOOL_TARGETS $i"
done
for i in click-install; do
    test -d $srcdir/tools/$i && TOOLDIRS="$TOOLDIRS $i"
done
AC_SUBST(TOOLDIRS)
AC_SUBST(TOOL_TARGETS)


dnl pcap library
dnl note: no longer need pcap under Linux

if test "$enable_userlevel" = yes; then
    CLICK_CHECK_LIBPCAP
    if test "$HAVE_PCAP" != yes -a "$ac_cv_under_linux" != yes; then
	AC_MSG_WARN([
=========================================

pcap.h and/or -lpcap not found; user-level driver can't steal packets.

=========================================])
    fi
    DRIVERS="$DRIVERS userlevel"
    AC_DEFINE(HAVE_USERLEVEL_DRIVER)
    HAVE_USERLEVEL_DRIVER=1
fi


dnl other user-level specifics

AC_CACHE_CHECK([whether struct if_data has ifi_datalen], [ac_cv_if_data_ifi_datalen],
    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <net/if.h>
#include <net/if_var.h>
]], [[struct if_msghdr ifm; ifm.ifm_data.ifi_datalen = 0;]])], ac_cv_if_data_ifi_datalen=yes, ac_cv_if_data_ifi_datalen=no)])
if test "x$ac_cv_if_data_ifi_datalen" = xyes; then
    AC_DEFINE([HAVE_IF_DATA_IFI_DATALEN], [1], [Define if 'struct if_data' has an 'ifi_datalen' member.])
fi

AC_CACHE_CHECK([whether struct sockaddr_in has sin_len], [ac_cv_sockaddr_in_sin_len],
    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>
#include <netinet/in.h>
]], [[struct sockaddr_in sin; sin.sin_len = 0;]])], ac_cv_sockaddr_in_sin_len=yes, ac_cv_sockaddr_in_sin_len=no)])
if test "x$ac_cv_sockaddr_in_sin_len" = xyes; then
    AC_DEFINE([HAVE_SOCKADDR_IN_SIN_LEN], [1], [Define if 'struct sockaddr_in' has a 'sin_len' member.])
fi


dnl PlanetLab "Privileged Operations" library

explicit_proper=yes
AC_ARG_WITH(proper, [[  --with-proper[=PREFIX]  use PlanetLab Proper library (optional)]],
  [properprefix=$withval; if test -z "$withval" -o "$withval" = yes; then properprefix=; fi],
  [properprefix=no; explicit_proper=no])
if test "$properprefix" != no; then
    dnl Proper requires libcurl
    dnl AC_CHECK_HEADER(curl/curl.h, have_curl_h=yes, have_curl_h=no)
    dnl AC_CHECK_LIB(curl, curl_easy_init)

    saveflags="$CPPFLAGS"; test -n "$properprefix" && CPPFLAGS="$CPPFLAGS -I$properprefix/include"
    AC_CHECK_HEADER(prop.h, have_prop_h=yes, have_prop_h=no)
    CPPFLAGS="$saveflags"
    
    AC_LANG_C
    saveflags="$LDFLAGS"; test -n "$properprefix" && LDFLAGS="$LDFLAGS -L$properprefix/lib"
    AC_CHECK_LIB(proper, prop_open, have_libproper=yes, have_libproper=no)
    LDFLAGS="$saveflags"
    AC_LANG_CPLUSPLUS

    if test $have_prop_h = yes -a $have_libproper = yes; then
	AC_DEFINE(HAVE_PROPER)
	test -n "$properprefix" && PROPER_INCLUDES="-I$properprefix/include" && PROPER_LIBS="-L$properprefix/lib"
	PROPER_LIBS="$PROPER_LIBS -lproper"
    elif test $explicit_proper = yes; then
	PROPER_INCLUDES= PROPER_LIBS=
	AC_MSG_ERROR([
=========================================

You explicitly specified --with-proper, but I can't find the proper headers
and/or libraries where you said they would be.  Run again supplying
--without-proper or --with-proper=PREFIX.

=========================================])
    fi
fi
AC_SUBST(PROPER_INCLUDES)
AC_SUBST(PROPER_LIBS)


dnl expat library

explicit_expat=yes
AC_ARG_WITH(expat, [[  --with-expat[=PREFIX]   locate expat XML library (optional)]],
  [expatprefix=$withval; if test -z "$withval" -o "$withval" = yes; then expatprefix=; fi],
  expatprefix=; explicit_expat=no)

XML2CLICK=
if test "$expatprefix" != no; then
    saveflags="$CPPFLAGS"; test -n "$expatprefix" && CPPFLAGS="$CPPFLAGS -I$expatprefix/include"
    AC_CHECK_HEADER(expat.h, have_expat_h=yes, have_expat_h=no)
    CPPFLAGS="$saveflags"
    
    AC_LANG_C
    saveflags="$LDFLAGS"; test -n "$expatprefix" && LDFLAGS="$LDFLAGS -L$expatprefix/lib"
    AC_CHECK_LIB(expat, XML_ParserCreateNS, have_libexpat=yes, have_libexpat=no)
    LDFLAGS="$saveflags"

    if test $have_expat_h = yes -a $have_libexpat = yes; then
	AC_DEFINE(HAVE_EXPAT)
	XML2CLICK=xml2click
	test -n "$expatprefix" && EXPAT_INCLUDES="-I$expatprefix/include" && EXPAT_LIBS="-L$expatprefix/lib"
	EXPAT_LIBS="$EXPAT_LIBS -lexpat"
    elif test $explicit_expat = yes; then
	EXPAT_INCLUDES= EXPAT_LIBS=
	AC_MSG_ERROR([
=========================================

You explicitly specified --with-expat, but I can't find the expat headers
and/or libraries where you said they would be.  Run again supplying
--without-expat or --with-expat=PREFIX.

=========================================])
    fi
fi
AC_SUBST(XML2CLICK)
AC_SUBST(EXPAT_INCLUDES)
AC_SUBST(EXPAT_LIBS)


dnl check linuxmodule for Linux

if test $ac_have_linux_kernel = y; then

    dnl check for Linux 2.6 #includes
    if test $LINUXMODULE_2_6 = 1; then
	AC_MSG_CHECKING([for Linux 2.6 compilation flags])
	echo "include $linuxdir/Makefile
fwablongie:
	@echo \$(CFLAGS)" >conftest.mk
	make -C "${linuxdir}" M="`pwd`" -f "`pwd`/conftest.mk" --no-print-directory fwablongie >conftest.dat
	if test $? != 0; then
	    AC_MSG_RESULT([not found])
	    AC_MSG_ERROR([
==============================================

Can't find Linux 2.6 compilation flags.

==============================================])
	fi
	LINUX_CFLAGS="`sed -e s,-Iinclude,-I$linuxdir/include,g \
	    -e 's,-W[^ ]*,,g' \
	    -e 's,-Wno-pointer-sign,,g' \
	    -e s,-fno-unit-at-a-time,,g \
	    -e s,-Wstrict-prototypes,,g \
	    -e s,-Wdeclaration-after-statement,,g \
	    -e s,-fno-common,,g <conftest.dat`"
	AC_MSG_RESULT($LINUX_CFLAGS)
    else
    	LINUX_CFLAGS=""
    fi
    AC_SUBST(LINUX_CFLAGS)


    SAVE_CXX="$CXX"
    CXX="$KERNEL_CXX"
    saveflags="$CPPFLAGS"
    CPPFLAGS="$saveflags -D__KERNEL__ -I$linuxdir/include $LINUX_CFLAGS"


    # CLICK_LINUXMODULE_PROLOGUE()
    AC_DEFUN([CLICK_LINUXMODULE_PROLOGUE], [[#if HAVE_LINUXMODULE_2_6
# define KBUILD_STR(s)		#s
# define KBUILD_BASENAME	KBUILD_STR(click)
# define KBUILD_MODNAME		KBUILD_STR(click)
#endif
#define new xxx_new
#define this xxx_this
#define delete xxx_delete
#define class xxx_class
#define virtual xxx_virtual
#define typename xxx_typename
#define private xxx_private
#define protected xxx_protected
#define public xxx_public
#define namespace xxx_namespace
#include <linux/autoconf.h>]])


    AC_CACHE_CHECK([for C++-includable kernel header files], [ac_cv_cxx_aware_system],
	[AC_LANG_CPLUSPLUS
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([CLICK_LINUXMODULE_PROLOGUE()[
#include <linux/signal.h>]], [[return 0]])], ac_cv_cxx_aware_system=yes, ac_cv_cxx_aware_system=no)
	])


    dnl check whether -fpermissive is required
    if test $ac_cv_cxx_aware_system = yes; then

	AC_CACHE_CHECK([whether -fpermissive is required], [ac_cv_f_permissive],
	    [AC_LANG_CPLUSPLUS
	    AC_LINK_IFELSE([AC_LANG_PROGRAM([CLICK_LINUXMODULE_PROLOGUE()[
#include <linux/skbuff.h>]], [[]])], ac_cv_f_permissive=no, ac_cv_f_permissive=yes)])

	if test $ac_cv_f_permissive = yes; then
	    CXX="$KERNEL_CXX -fpermissive"
	    AC_CACHE_CHECK([whether -fpermissive is allowed], [ac_cv_f_permissive_ok],
		[AC_LANG_CPLUSPLUS
		AC_LINK_IFELSE([AC_LANG_PROGRAM([CLICK_LINUXMODULE_PROLOGUE()[
#include <linux/skbuff.h>]], [[]])], ac_cv_f_permissive_ok=yes, ac_cv_f_permissive_ok=no)])

	    if test $ac_cv_f_permissive_ok = no; then
		ac_cv_cxx_aware_system=no
	    else
		KERNEL_CXX="$KERNEL_CXX -fpermissive"
	    fi
	fi
    fi


    AC_CACHE_CHECK([whether long and int64_t are the same type in the Linux kernel],
	ac_cv_long_64_linuxmodule, [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([CLICK_LINUXMODULE_PROLOGUE()[
#include <linux/types.h>
void f1(long) {
}
void f1(int64_t) { // will fail if long and int64_t are the same type
}]], [[]])], ac_cv_long_64_linuxmodule=no, ac_cv_long_64_linuxmodule=yes)])
    if test $ac_cv_long_64_linuxmodule = yes; then
	AC_DEFINE([HAVE_INT64_IS_LONG_LINUXMODULE], [1], [Define if 'int64_t' is typedefed to 'long' in linuxmodule.])
    fi


    AC_CACHE_CHECK([whether long long and int64_t are the same type in the Linux kernel],
	ac_cv_long_long_64_linuxmodule, [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([CLICK_LINUXMODULE_PROLOGUE()[
#include <linux/types.h>
void f1(long long) {
}
void f1(int64_t) { // will fail if long long and int64_t are the same type
}]], [[]])], ac_cv_long_long_64_linuxmodule=no, ac_cv_long_long_64_linuxmodule=yes)])
    if test $ac_cv_long_long_64_linuxmodule = yes; then
	AC_DEFINE([HAVE_INT64_IS_LONG_LONG_LINUXMODULE], [1], [Define if 'int64_t' is typedefed to 'long long' in linuxmodule.])
    fi


    AC_CACHE_CHECK([whether struct sk_buff has a security member], [ac_cv_linuxmodule_skbuff_security],
	[AC_LANG_C
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([CLICK_LINUXMODULE_PROLOGUE()[
#include <linux/skbuff.h>]],
[[extern struct sk_buff *s; s->security = 0;]])], 
	[ac_cv_linuxmodule_skbuff_security=yes], [ac_cv_linuxmodule_skbuff_security=no])])
    if test $ac_cv_linuxmodule_skbuff_security = yes; then
	AC_DEFINE([HAVE_LINUX_SKBUFF_SECURITY], [1], [Define if 'struct sk_buff' has a 'security' member.])
    fi

    AC_CACHE_CHECK([whether struct sk_buff has an fclone member], [ac_cv_linuxmodule_skbuff_fclone],
	[AC_LANG_C
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([CLICK_LINUXMODULE_PROLOGUE()[
#include <linux/skbuff.h>]],
[[extern struct sk_buff *s; s->fclone = 0;]])], 
	[ac_cv_linuxmodule_skbuff_fclone=yes], [ac_cv_linuxmodule_skbuff_fclone=no])])
    if test $ac_cv_linuxmodule_skbuff_fclone = yes; then
	AC_DEFINE([HAVE_LINUX_SKBUFF_FCLONE], [1], [Define if 'struct sk_buff' has an 'fclone' member.])
    fi

    AC_CACHE_CHECK([whether skb_shinfo has a tso_size member], [ac_cv_linuxmodule_skb_shinfo_tso_size],
	[AC_LANG_C
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([CLICK_LINUXMODULE_PROLOGUE()[
#include <linux/skbuff.h>]],
[[extern struct sk_buff *s; skb_shinfo(s)->tso_size = 0;]])],
	[ac_cv_linuxmodule_skb_shinfo_tso_size=yes], [ac_cv_linuxmodule_skb_shinfo_tso_size=no])])
    if test $ac_cv_linuxmodule_skb_shinfo_tso_size = yes; then
	AC_DEFINE([HAVE_LINUX_SKB_SHINFO_TSO_SIZE], [1], [Define if 'struct skb_shared_info' has a 'tso_size' member.])
    fi

    AC_CACHE_CHECK([whether skb_shinfo has a gso_size member], [ac_cv_linuxmodule_skb_shinfo_gso_size],
	[AC_LANG_C
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([CLICK_LINUXMODULE_PROLOGUE()[
#include <linux/skbuff.h>]],
[[extern struct sk_buff *s; skb_shinfo(s)->gso_size = 0;]])],
	[ac_cv_linuxmodule_skb_shinfo_gso_size=yes], [ac_cv_linuxmodule_skb_shinfo_gso_size=no])])
    if test $ac_cv_linuxmodule_skb_shinfo_gso_size = yes; then
	AC_DEFINE([HAVE_LINUX_SKB_SHINFO_GSO_SIZE], [1], [Define if 'struct skb_shared_info' has a 'gso_size' member.])
    fi

    AC_CACHE_CHECK([whether skb_shinfo has a ufo_size member], [ac_cv_linuxmodule_skb_shinfo_ufo_size],
	[AC_LANG_C
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([CLICK_LINUXMODULE_PROLOGUE()[
#include <linux/skbuff.h>]],
[[extern struct sk_buff *s; skb_shinfo(s)->ufo_size = 0;]])],
	[ac_cv_linuxmodule_skb_shinfo_ufo_size=yes], [ac_cv_linuxmodule_skb_shinfo_ufo_size=no])])
    if test $ac_cv_linuxmodule_skb_shinfo_ufo_size = yes; then
	AC_DEFINE([HAVE_LINUX_SKB_SHINFO_UFO_SIZE], [1], [Define if 'struct skb_shared_info' has a 'ufo_size' member.])
    fi

    AC_CACHE_CHECK([whether skb_shinfo has an ip6_frag_id member], [ac_cv_linuxmodule_skb_shinfo_ip6_frag_id],
	[AC_LANG_C
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([CLICK_LINUXMODULE_PROLOGUE()[
#include <linux/skbuff.h>]],
[[extern struct sk_buff *s; skb_shinfo(s)->ip6_frag_id = 0;]])],
	[ac_cv_linuxmodule_skb_shinfo_ip6_frag_id=yes], [ac_cv_linuxmodule_skb_shinfo_ip6_frag_id=no])])
    if test $ac_cv_linuxmodule_skb_shinfo_ip6_frag_id = yes; then
	AC_DEFINE([HAVE_LINUX_SKB_SHINFO_IP6_FRAG_ID], [1], [Define if 'struct skb_shared_info' has an 'ip6_frag_id' member.])
    fi

    AC_LANG_C
    AC_CHECK_DECL(net_enable_timestamp, [ac_cv_net_enable_timestamp=yes], [ac_cv_net_enable_timestamp=no], [CLICK_LINUXMODULE_PROLOGUE()[
#include <linux/skbuff.h>
#include <linux/netdevice.h>]])
    if test $ac_cv_net_enable_timestamp = yes; then
	AC_DEFINE([HAVE_NET_ENABLE_TIMESTAMP], [1], [Define if you have the 'net_enable_timestamp' function.])
    fi

    AC_CHECK_DECL(netif_tx_lock, [ac_cv_netif_tx_lock=yes], [ac_cv_netif_tx_lock=no], [CLICK_LINUXMODULE_PROLOGUE()[
#include <linux/skbuff.h>
#include <linux/netdevice.h>]])
    if test $ac_cv_netif_tx_lock = yes; then
	AC_DEFINE([HAVE_NETIF_TX_LOCK], [1], [Define if you have the 'netif_tx_lock' function.])
    fi


    CXX="$SAVE_CXX"
    CPPFLAGS="$saveflags"

    if test $ac_cv_cxx_aware_system = yes; then
	DRIVERS="$DRIVERS linuxmodule"
	TOOL_TARGETS="$TOOL_TARGETS click-install"
	AC_DEFINE(HAVE_LINUXMODULE_DRIVER)
	HAVE_LINUXMODULE_DRIVER=1
    elif test x$enable_linuxmodule_default = xyes; then
	AC_MSG_WARN([
=========================================

Your Linux kernel header files cause errors when included by a C++ program,
so I won't try to compile the linuxmodule driver.

There are two common reasons for this error:
1. You have not applied the Linux kernel patch that comes with this
   distribution.  Apply the right patch and try again.  See the INSTALL
   file for more information.
2. Your Linux configuration enables some functionality that is not yet
   covered by our patches.  Turn off this functionality and try again,
   or fix the error and tell us how you did it.  See the config.log file
   for more detailed information on the error.

=========================================])
    else
	AC_MSG_ERROR([
=========================================

Your Linux kernel header files cause errors when included by a C++ program.

There are two common reasons for this error:
1. You have not applied the Linux kernel patch that comes with this
   distribution.  Apply the right patch and try again.  See the INSTALL
   file for more information.
2. Your Linux configuration enables some functionality that is not yet
   covered by our patches.  Turn off this functionality and try again,
   or fix the error and tell us how you did it.  See the config.log file
   for more detailed information on the error.

=========================================])
    fi
fi


dnl check bsdmodule for BSD

if test $ac_have_bsd_kernel = y; then
    DRIVERS="$DRIVERS bsdmodule"
    if echo "$DRIVERS" | grep linuxmodule >/dev/null 2>&1; then :; else
	TOOL_TARGETS="$TOOL_TARGETS click-install"
    fi
    AC_DEFINE(HAVE_BSDMODULE_DRIVER)
    HAVE_BSDMODULE_DRIVER=1
fi


dnl check ns

if test "x$enable_nsclick" = xyes; then
    DRIVERS="$DRIVERS ns"
fi


dnl check tools

if test "x$enable_tools" != xno; then
    OTHER_TARGETS="$OTHER_TARGETS tools"
fi


dnl
dnl programs needed for build process
dnl

CLICK_PROG_INSTALL
CLICK_PROG_GMAKE
CLICK_PROG_AUTOCONF
CLICK_PROG_PERL5

if test -z "$GMAKE"; then
    AC_MSG_ERROR([
==============================================

Can't find GNU make.  Either put 'gmake' on your PATH and
rerun './configure', or set the GMAKE environment variable to
GNU make's pathname.

==============================================])
fi


dnl
dnl Makeinfo, texi2dvi, install-info, pod2man
dnl

AC_MSG_CHECKING(for working makeinfo)
MAKEINFO=${MAKEINFO-makeinfo}
if ($MAKEINFO --version) < /dev/null > conftest.out 2>&1; then
    if test `head -n 1 conftest.out | sed 's/^.* \([[0-9]][[0-9]]*\).*$/\1/'` -ge 4; then
	AC_MSG_RESULT(found)
    else
	MAKEINFO='$(conf_auxdir)/missing makeinfo'
	AC_MSG_RESULT(old)
    fi
else
    MAKEINFO='$(conf_auxdir)/missing makeinfo'
    AC_MSG_RESULT(missing)
fi

AC_MSG_CHECKING(for working texi2dvi)
TEXI2DVI=${TEXI2DVI-texi2dvi}
if ($TEXI2DVI --version) < /dev/null > conftest.out 2>&1; then
    dnl Search for a good version of texi2dvi
    if test `head -n 1 conftest.out | sed 's/.*Texinfo \([[0-9]][[0-9]]*\).*/\1/'` -ge 4; then
	AC_MSG_RESULT(found)
    else
	TEXI2DVI='$(conf_auxdir)/missing texi2dvi'
	AC_MSG_RESULT(old)
    fi
else
    TEXI2DVI='$(conf_auxdir)/missing texi2dvi'
    AC_MSG_RESULT(missing)
fi

dnl Assume any version of install-info is OK
if test ${INSTALL_INFO-xxx} = xxx; then
    AC_PATH_PROG(INSTALL_INFO, install-info, '$(conf_auxdir)/missing install-info',
	$PATH:/sbin:/usr/sbin:/usr/local/sbin)
fi
AC_MSG_CHECKING(for working install-info)
if ($INSTALL_INFO --version) < /dev/null > conftest.out 2>&1; then
    AC_MSG_RESULT(found)
else
    INSTALL_INFO='$(conf_auxdir)/missing install-info'
    AC_MSG_RESULT(missing)
fi

AC_MSG_CHECKING(for working pod2man)
POD2MAN=${POD2MAN-pod2man}
if ($POD2MAN --help) < /dev/null > conftest.out 2>&1 && grep pod2man conftest.out >/dev/null 2>&1; then
    AC_MSG_RESULT(found)
else
    POD2MAN='$(conf_auxdir)/missing pod2man'
    AC_MSG_RESULT(missing)
fi


AC_SUBST(MAKEINFO)
AC_SUBST(TEXI2DVI)
AC_SUBST(INSTALL_INFO)
AC_SUBST(POD2MAN)


dnl
dnl set path variables
dnl

shell_expand () {
    val=`eval echo '$'"$1"`
    while echo "x$val" | fgrep '$' >/dev/null 2>&1; do val=`eval echo "$val"`; done
    eval "$1='$val'"
}

dnl Preset $prefix and $exec_prefix.
test "x$prefix" = xNONE && prefix=$ac_default_prefix
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'

dnl Expand 'infodir' to check for Red Hat
if test x$infodir = 'x${prefix}/info'; then
    test ! -d ${prefix}/info && test -d ${prefix}/share/info && infodir='${prefix}/share/info'
fi

shell_expand bindir
shell_expand sbindir
shell_expand libdir
shell_expand datarootdir
shell_expand datadir
shell_expand includedir

clickdatadir="$datadir/click"
AC_SUBST(clickdatadir)

AC_DEFINE_UNQUOTED(CLICK_BINDIR, "$bindir")
AC_DEFINE_UNQUOTED(CLICK_LIBDIR, "$libdir")
AC_DEFINE_UNQUOTED(CLICK_DATADIR, "$clickdatadir")


dnl
dnl Provisions
dnl

dnl start out with CPU
provisions="$target_cpu"
case "$target_cpu" in
    i386) :;;
    i486|i586) provisions="$provisions i386";;
    i686|i786) provisions="$provisions i386 i586";;
esac

dnl add 'analysis' if analysis elements are available
if test "x$enable_analysis" = xyes; then
    provisions="$provisions analysis"
fi

dnl add 'experimental' if --enable-experimental was supplied
if test "x$enable_experimental" = xyes; then
    provisions="$provisions experimental"
fi

dnl add 'int64' if 64-bit integers are available
if test "x$have_int64_types" = xyes; then
    provisions="$provisions int64"
fi

dnl add 'ip6' if ip6 elements are available
if test "x$enable_ip6" = xyes; then
    provisions="$provisions ip6"
fi

dnl add 'linux' if compiling under linux
if test "x$ac_cv_under_linux" = xyes; then
    provisions="$provisions linux"
fi

dnl add provision for linux kernel version
if test $ac_have_linux_kernel = y; then
    ac_linux_version_code=`grep LINUX_VERSION_CODE $linuxdir/include/linux/version.h | sed 's/^.*CODE //'`
    if test $ac_linux_version_code -ge 131584 -a $ac_linux_version_code -lt 131840; then
	provisions="$provisions linux_2_2"
    elif test $ac_linux_version_code -ge 132096 -a $ac_linux_version_code -lt 132352; then
	provisions="$provisions linux_2_4"
    elif test $ac_linux_version_code -ge 132608 -a $ac_linux_version_code -lt 132864; then
	provisions="$provisions linux_2_6"
    fi
fi

dnl add 'pcap' if libpcap is available
if test "x$HAVE_PCAP" = xyes; then
    provisions="$provisions pcap"
fi

dnl add 'smpclick' if compiled with --enable-multithread > 1
if test "$enable_multithread" -gt 1; then
    provisions="$provisions smpclick"
fi

dnl add 'umultithread' if compiled with --enable-user-multithread
if test "x$enable_user_multithread" = xyes; then
    provisions="$provisions umultithread"
fi

dnl add 'wifi' if wifi elements are available
if test "x$enable_wifi" = xyes; then
    provisions="$provisions wifi"
fi

AC_SUBST(provisions)

dnl
dnl Output
dnl

config_files="Makefile click-buildtool click-compile config.mk installch tools/Makefile tools/lib/Makefile doc/Makefile etc/libclick/Makefile etc/pkg-config.mk"
for ac_dir in $POSSIBLE_DRIVERS; do
    config_files="$config_files $ac_dir/Makefile"
done
for ac_dir in $TOOLDIRS; do
    config_files="$config_files tools/$ac_dir/Makefile"
done
for ac_dir in etc include; do
    test ! -d "$ac_dir" && mkdir "$ac_dir"
done

AC_OUTPUT_COMMANDS([for ac_file in $CONFIG_HEADERS; do
    test $ac_file = include/click/config.h:config.h.in && echo > stamp-h
done
for ac_file in $CONFIG_FILES; do
    test $ac_file = click-buildtool && chmod +x click-buildtool
    test $ac_file = click-compile && chmod +x click-compile
    test $ac_file = installch && chmod +x installch
done])
AC_OUTPUT($config_files)
